package com.gs.disk.modules.headImgAndWallper.controller.admin;


import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.gs.entity.GeneralPage;
import com.gs.entity.R;
import com.gs.disk.modules.headImgAndWallper.entity.CategoryEntity;
import com.gs.disk.modules.headImgAndWallper.service.admin.AdminCategoryService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("disk/admin/category")
@Api(tags = "后台分类管理")
@ApiSort(3)
public class AdminCategoryController {

    @Resource
    private AdminCategoryService service;



    @GetMapping("list")
//    @Cacheable(value = "list", keyGenerator = "myKeyGenerator")
    public R categoryList(@RequestParam(required = false) String categoryName,
                          @RequestParam Long page,
                          @RequestParam Long limit) {
        GeneralPage<CategoryEntity> list = service.list(categoryName, page, limit);

        return R.ok(list);
    }

    @PutMapping("save")
    public R save(@RequestBody CategoryEntity entity,@RequestParam("file") MultipartFile file) {

        service.save(entity);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R delete(@RequestParam Long id) {
        service.delete(id);
        return R.ok();
    }
}
